package cn.yh.register.order.controller;

import cn.yh.register.common.result.Result;
import cn.yh.register.enums.OrderStatusEnum;
import cn.yh.register.model.order.OrderInfo;
import cn.yh.register.order.service.OrderService;
import cn.yh.register.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(value = "后台管理订单")
@RestController
@RequestMapping("/admin/order/orderInfo")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("后台获取订单列表")
    @GetMapping("{page}/{limit}")
    public Result<IPage<OrderInfo>> getOrderList(@PathVariable Long page,
                                 @PathVariable Long limit,
                                 OrderQueryVo orderQueryVo){
        Page<OrderInfo> orderInfoPage = new Page<>(page, limit);
        IPage<OrderInfo> infoIPage = orderService.selectPage(orderInfoPage, orderQueryVo);
        return Result.ok(infoIPage);
    }

    @ApiOperation(value = "后台获取订单详情")
    @GetMapping("show/{id}")
    public Result<Map<String, Object>> get(@PathVariable Long id) {
        Map<String, Object> orderInfo = orderService.getOrderInfo(id);
        return Result.ok(orderInfo);
    }

    @ApiOperation(value = "获取订单状态")
    @GetMapping("getStatusList")
    public Result<?> getStatusList() {
        return Result.ok(OrderStatusEnum.getStatusList());
    }
}
